export default {
	methods: {
		GetImgwOrderLoad() {
			let tmpImgRemark=''
			this.WoItemPictures = [];
			let pages = getCurrentPages();
			let prevPageData = pages[pages.length - 2].data;
			if (prevPageData.hasOwnProperty("orderDetailData")) {
				let orderDetailData = prevPageData.orderDetailData;
				this.wOrderId = orderDetailData.WoId;
				for (let itemPicIndex in orderDetailData.WoItemPicture) {
					//debugger;
					if(!tmpImgRemark){
						tmpImgRemark =  orderDetailData.WoItemPicture[itemPicIndex].Description
						this.imgRemark= tmpImgRemark
					}
					this.WoItemPictures.push(orderDetailData.WoItemPicture[itemPicIndex])
				}
				console.log(this.WoItemPictures);
			}
		},

		GetImgwOrderReLoad() {
			let tmpImgRemark=''
			this.WoItemPictures = [];
			this.WOPictureDetailsAsync().then((success) => {
				let {
					RetObject,
					RetBool,
					RetMsg
				} = success;
				if (RetBool) {
					let picList = JSON.parse(RetObject);
					for (let picIndex in picList) {
						if(!tmpImgRemark){
							tmpImgRemark = picList[picIndex].Description
							this.imgRemark= tmpImgRemark
						}
						//picList[picIndex]["ImageContent"] = picList[picIndex].FileContent;
					}
					this.WoItemPictures = picList;
					uni.$emit("reLoadInstall");
					uni.hideLoading();
					uni.showToast({
						icon: "none",
						title: "上传成功"
					})
				} else {
					uni.hideLoading();
				}
			}).catch((error) => {
				uni.hideLoading();
			})
		},

		getImageBase64(itempic) {
			let srcbase64 = `data:image/${itempic.FileType.replace('.','')};base64,${itempic.ImageContent||itempic.FileContent}`;
			return srcbase64;
		},

		imagePathToBase64(imgTempPath) {
			let fileSysManager = uni.getFileSystemManager()
			return fileSysManager.readFileSync(imgTempPath, "base64");
		},

		async WOPictureUploadInBatchAsync(imgbase64List) {
			let userPhone = this.UserInfo.mobile;
			let token = this.UserInfo.RetId;
			//debugger;
			let result = await this.workordercompleteservice.WOPictureUploadInBatchAsync(userPhone,
				this.wOrderId, imgbase64List, token);
			return result;
		},

		async WOPictureDetailsAsync() {
			let userPhone = this.UserInfo.mobile;
			let token = this.UserInfo.RetId;
			let worderId = this.wOrderId;
			let result = await this.workordercompleteservice
				.WOPictureDetailsAsync(userPhone, worderId, token);
			return result;
		},

		async WOPictureDeleteInBatchAsync(DeletedImages) {
			let userPhone = this.UserInfo.mobile;
			let token = this.UserInfo.RetId;
			let worderId = this.wOrderId;
			let result = await this.workordercompleteservice
				.WOPictureDeleteInBatchAsync(userPhone, worderId,
					DeletedImages, token);
			return result;
		},

		async GetUserLocation(callback) {
			try {
				let {
					latitude,
					longitude,
					errMsg
				} = await this.uniApiPromise.GetLocationPromise();
				this.getLocationAddress(longitude, latitude).then((success) => {
					let {result,status,message} = success;
					this.currAddress = result.address;
					//console.log(result.address);
				})

			} catch (error) {
				if (error.errMsg == "getLocation:fail auth deny") {
					let modelRes = await this.uniApiPromise.showModalPromise();
					if (modelRes && modelRes.confirm) {
						uni.hideLoading();
						let settingRes = await this.uniApiPromise.OpenSettingPromise();
						if (settingRes &&
							settingRes.authSetting["scope.userLocation"] === true) {
							let {
								latitude,
								longitude,
								errMsg
							} = await this.uniApiPromise.GetLocationPromise();
							this.getLocationAddress(longitude, latitude).then((success) => {
								let {result,status,message} = success
								this.currAddress = result.address;
								//console.log(result.address)
							})

						} else {
							uni.hideLoading();
						}
					} else {
						uni.hideLoading();
						uni.showToast({
							icon: "none",
							title: "没有授权"
						})
					}
				}
			}
		},

		//根据经纬度查出地址名称
		async getLocationAddress(lon, lat) {
			let params = {
				location: `${lat},${lon}`
			}
			let result = await this.mapApiService
				.geoMultipParamMapAsync(this.qqMapServiceUrl, "/ws/geocoder/v1", params);
			return result;
		},

	}
}
